home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / hopes_babysitting_maze.swf / scripts / __Packages / smashing / IntervalEngine.as next >
Text File  |  2011-08-19  |  2KB  |  80 lines

  1. class smashing.IntervalEngine
  2. {
  3.    var _MAX_TIMEDIFF = 0.005;
  4.    var _MIN_FPS = 5;
  5.    var _MAX_FRAMETIME = 1 / smashing.IntervalEngine.prototype._MIN_FPS;
  6.    var _lel = 0.2;
  7.    var _FPS = 0;
  8.    var _is_paused = false;
  9.    function IntervalEngine(update_object, update_function)
  10.    {
  11.       this._uo = update_object;
  12.       this._uf = update_function;
  13.    }
  14.    function startFlat(FPS)
  15.    {
  16.       this._FPS = FPS;
  17.       this._update_interval = 1 / FPS;
  18.       this._i = setInterval(this,"_flat_step",0);
  19.    }
  20.    function startFlex()
  21.    {
  22.       this._last_update = getTimer() * 0.001;
  23.       this._i = setInterval(this,"_flex_step",0);
  24.    }
  25.    function startFast()
  26.    {
  27.       this._last_update = getTimer() * 0.001;
  28.       this._i = setInterval(this,"_fast_step",0);
  29.    }
  30.    function pause(Void)
  31.    {
  32.       this._is_paused = true;
  33.    }
  34.    function unpause(Void)
  35.    {
  36.       this._is_paused = false;
  37.    }
  38.    function reset(Void)
  39.    {
  40.       if(this._i != undefined)
  41.       {
  42.          clearInterval(this._i);
  43.       }
  44.       this._ft = 0;
  45.       this._last_update = getTimer() * 0.001;
  46.       this._lel = this._MAX_FRAMETIME / 2;
  47.       this.pause();
  48.    }
  49.    function _flex_step(Void)
  50.    {
  51.       if(this._is_paused)
  52.       {
  53.          this._last_update = getTimer() * 0.001;
  54.          return undefined;
  55.       }
  56.       this._el = Math.min(this._MAX_FRAMETIME,- this._last_update + (this._last_update = getTimer() * 0.001));
  57.       this._lel -= Math.max(- this._MAX_TIMEDIFF,Math.min(this._MAX_TIMEDIFF,this._lel - this._el));
  58.       this._uo[this._uf](this._lel);
  59.    }
  60.    function _flat_step(Void)
  61.    {
  62.       if(this._is_paused)
  63.       {
  64.          return undefined;
  65.       }
  66.       this._ft += - this._last_update + (this._last_update = getTimer() * 0.001);
  67.       if(this._ft < this._update_interval)
  68.       {
  69.          return undefined;
  70.       }
  71.       this._uo[this._uf](this._ft);
  72.       this._ft = 0;
  73.    }
  74.    function _fast_step(Void)
  75.    {
  76.       this._el = - this._last_update + (this._last_update = getTimer());
  77.       this._uo[this._uf](this._el * 0.001);
  78.    }
  79. }
  80.